Skip to content

Fix lab verifier path traversal in lab runtime#21

Open
beyildirim wants to merge 5 commits intomainfrom
fix/verify-path-injection
Open

Fix lab verifier path traversal in lab runtime#21
beyildirim wants to merge 5 commits intomainfrom
fix/verify-path-injection

Conversation

@beyildirim
Copy link
Copy Markdown
Owner

This fixes the open CodeQL path-injection finding in weaklink_platform/lab_runtime.py by resolving verifier paths under an allowed root before touching verify.py.

Changes:

  • Added descendant path confinement before resolving the lab verifier path.
  • Fail closed with an invalid lab path error when a lab id escapes the configured labs root.
  • Added a regression test for traversal-style lab ids.

Validation:

  • python3 -m pytest tests/platform/test_lab_runtime.py
  • python3 -m ruff check weaklink_platform/lab_runtime.py tests/platform/test_lab_runtime.py



def _validated_lab_id(lab_id: str) -> str:
if not LAB_ID_PATTERN.fullmatch(lab_id):
Comment thread weaklink_platform/lab_runtime.py Fixed
safe_lab_id = _validated_lab_id(lab_id)
resolved_lab_dir = (resolved_labs_root / safe_lab_id).resolve(strict=False)
resolved_lab_dir.relative_to(resolved_labs_root)
python_verifier = (resolved_lab_dir / "verify.py").resolve(strict=False)
beyildirim and others added 3 commits April 14, 2026 23:24
…ed in path expression'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
try:
resolved_labs_root = labs_root.resolve(strict=False)
safe_lab_id = _validated_lab_id(lab_id)
expected_lab_dir = (resolved_labs_root / safe_lab_id).resolve(strict=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants